﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model.Db.System;


namespace HengTong.ViewModel._Admin.SysCodeHistoryVms
{
    public partial class SysCodeHistoryListVm : BasePagedListVM<SysCodeHistoryView, SysCodeHistorySearcher>
    {

        protected override IEnumerable<IGridColumn<SysCodeHistoryView>> InitGridHeader()
        {
            return new List<GridColumn<SysCodeHistoryView>>{
                this.MakeGridHeader(x => x.CodeRuleName),
                this.MakeGridHeader(x => x.GeneratedCode),
                this.MakeGridHeader(x => x.BusinessType),
                this.MakeGridHeader(x => x.SerialNumber),
                this.MakeGridHeader(x => x.GenerateTime),
                this.MakeGridHeader(x => x.Operator),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeader(x => x.TenantCode),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysCodeHistoryView> GetSearchQuery()
        {
            var query = DC.Set<SysCodeHistory>()
                .CheckEqual(Searcher.CodeRuleId, x=>x.CodeRuleId)
                .CheckContain(Searcher.GeneratedCode, x=>x.GeneratedCode)
                .CheckContain(Searcher.BusinessType, x=>x.BusinessType)
                .Select(x => new SysCodeHistoryView
                {
				    ID = x.ID,
                    CodeRuleName = x.CodeRule.Name,
                    GeneratedCode = x.GeneratedCode,
                    BusinessType = x.BusinessType,
                    SerialNumber = x.SerialNumber,
                    GenerateTime = x.GenerateTime,
                    Operator = x.Operator,
                    Remark = x.Remark,
                    TenantCode = x.TenantCode,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysCodeHistoryView : SysCodeHistory{
        [Display(Name = "编码名称")]
        public String CodeRuleName { get; set; }

    }
}
